import React from 'react'
import {message, Modal} from 'antd';
import {ExclamationCircleOutlined} from '@ant-design/icons';
import {deleteArticle} from "../../requests/article";


//解构出confirm
const { confirm } = Modal;
export default function deleteArticleModal(articleID: number, title: string, refresh: () => void) {
    confirm({
        title: `确认删除 ${title} 吗`,
        icon: <ExclamationCircleOutlined />,
        content: '删除后请在回收站查看',
        onOk() {
            return deleteArticle(articleID).then(msg => {
                if (msg.data.isSuccessful) {
                    message.success('删除成功')
                    refresh()
                }
                else {
                    message.error('删除失败')
                }
            }).catch((err) => {
                console.log(err)
            })
        },
        onCancel() { },
    });
}